﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using RpgLibrary.ItemClasses;
using RpgLibrary;

namespace RpgEditor
{
    public partial class FormKeyDetails : FormDetailBase, IDetailForm
    {
        
        #region Field Region
        
        KeyData key;
        
        #endregion

        #region Property Region
        
        public KeyData Key
        {
            get { return key; }
            set { key = value; }
        }

        public override IRpgDataObject DataObject
        {
            get
            {
                return (IRpgDataObject)key;
            }
            set
            {
                key = (KeyData)value;
            }
        }


        #endregion

        public FormKeyDetails()
        {
            InitializeComponent();

            SetDataObjectValueFunction = SetKeyValue;
            LoadDataObjectValueFunction = LoadKeyValue;
        }

        #region Method Region

        void LoadKeyValue()
        {
            if (key != null)
            {
                tbName.Text = key.Name;
                tbType.Text = key.Type;
            }
        }
        
        bool SetKeyValue()
        {
            if (string.IsNullOrEmpty(tbName.Text))
            {
                MessageBox.Show("You must enter a name for the item.");
                return false;
            }

            key = new KeyData();
            key.Name = tbName.Text;
            key.Type = tbType.Text;
            
            return true;
        }

        #endregion
    }
}
